import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import App from './App.vue'
// import router from './router'
import routes from './router'
import store from './store'
// createApp(App).use(store).use(router).mount('#app')
let history
let router
let app
// 挂载到自己的html中，基座会拿到这个挂载后的html插入进去
function render(props = {}) {
    // 创建router,baseurl为/vue
    history = createWebHistory('/vue') // 保持路由配置 
    router = createRouter({ // 保持路由实例
        history,
        routes
    })
    app = createApp(App) // 创建app
    // props里包含主应用传来的信息
    let { container } = props // 拿到20000端口的html插入到容器
    app.use(store).use(router).mount(container ? container.querySelector('#app') : '#app')
}
// 独立运行
if (!window.__POWERED_BY_QIANKUN__) {
    render()
}
// 需要暴露接入协议
// 子组件的协议，必须暴露三个函数
export async function bootstrap(props) {
    console.log('bootstrap函数:', props)
}
export async function mount(props) {
    console.log('mount函数:', props)
    render(props)
}
export async function unmount(props) {
    console.log('unmount函数:', props)
    // instance.$destroy()
    history = null
    router = null
    app = null
} 